package net.minecraft.src;

import java.util.Random;

public class PPHGenSigillaria extends WorldGenerator
{

    public PPHGenSigillaria()
    {
    }

    public boolean generate(World world, Random random, int i, int j, int k)
    {
	if(world.getBlockId(i, j - 1, k) == mod_pph.prehistoricGrass.blockID && world.isAirBlock(i, j + 12, k))
	{
		for(int width = 0; width < 1; width++)
		{
			for(int height = 0; height < 22; height++)
			{
				for(int depth = 0; depth < 1; depth++)
				{
					world.setBlockAndMetadata(i+width, j+height, k+depth, mod_pph.prehistoricWood.blockID, 3);
				}
			}
		}
		int l = random.nextInt(3);
		if(l == 0)
		{
			generateBranches(world, random, i, j + 21, k, 0);
		}
		if(l == 1)
		{
			generateBranches(world, random, i, j + 21, k, 1);
		}
		if(l == 2)
		{
			generateBranches(world, random, i, j + 21, k, 2);
		}
	}
		return true;
	}
	
	private boolean generateBranches(World world, Random random, int i, int j, int k, int l)
	{
	if(l == 0)
	{
	for(int width = 0; width < 1; width++)
	{
		for(int height = 0; height < 5; height++)
		{
			for(int depth = 0; depth < 1; depth++)
			{
				world.setBlockAndMetadata(i+width, j+height, k+depth, mod_pph.prehistoricWood.blockID, 3);
				world.setBlockAndMetadata(i+width, j+height+1, k+depth, mod_pph.prehistoricLeaves.blockID, 0);
			}
		}
	}
		generateLeaves(world, random, i, j + 1, k);
	}
	if(l == 1)
	{
	world.setBlockAndMetadata(i, j + 1, k + 1, mod_pph.prehistoricWood.blockID, 3);
	world.setBlockAndMetadata(i, j + 2, k + 2, mod_pph.prehistoricWood.blockID, 3);
	world.setBlockAndMetadata(i, j + 3, k + 3, mod_pph.prehistoricWood.blockID, 3);
	
	world.setBlockAndMetadata(i, j + 1, k - 1, mod_pph.prehistoricWood.blockID, 3);
	world.setBlockAndMetadata(i, j + 2, k - 2, mod_pph.prehistoricWood.blockID, 3);
	world.setBlockAndMetadata(i, j + 3, k - 3, mod_pph.prehistoricWood.blockID, 3);
	for(int width = 0; width < 1; width++)
	{
		for(int height = 3; height < 8; height++)
		{
			for(int depth = -3; depth < -2; depth++)
			{
				world.setBlockAndMetadata(i+width, j+height, k+depth, mod_pph.prehistoricWood.blockID, 3);
				world.setBlockAndMetadata(i+width, j+height+1, k+depth, mod_pph.prehistoricLeaves.blockID, 0);
			}
		}
	}
	for(int width = 0; width < 1; width++)
	{
		for(int height = 3; height < 8; height++)
		{
			for(int depth = 3; depth < 4; depth++)
			{
				world.setBlockAndMetadata(i+width, j+height, k+depth, mod_pph.prehistoricWood.blockID, 3);
				world.setBlockAndMetadata(i+width, j+height+1, k+depth, mod_pph.prehistoricLeaves.blockID, 0);
			}
		}
	}
		generateLeaves(world, random, i, j + 4, k + 3);
		generateLeaves(world, random, i, j + 4, k - 3);
	}
	if(l == 2)
	{
	world.setBlockAndMetadata(i + 1, j + 1, k, mod_pph.prehistoricWood.blockID, 3);
	world.setBlockAndMetadata(i + 2, j + 2, k, mod_pph.prehistoricWood.blockID, 3);
	world.setBlockAndMetadata(i + 3, j + 3, k , mod_pph.prehistoricWood.blockID, 3);
	
	world.setBlockAndMetadata(i - 1, j + 1, k, mod_pph.prehistoricWood.blockID, 3);
	world.setBlockAndMetadata(i - 2, j + 2, k, mod_pph.prehistoricWood.blockID, 3);
	world.setBlockAndMetadata(i - 3, j + 3, k, mod_pph.prehistoricWood.blockID, 3);
	for(int width = -3; width < -2; width++)
	{
		for(int height = 3; height < 8; height++)
		{
			for(int depth = 0; depth < 1; depth++)
			{
				world.setBlockAndMetadata(i+width, j+height, k+depth, mod_pph.prehistoricWood.blockID, 3);
				world.setBlockAndMetadata(i+width, j+height+1, k+depth, mod_pph.prehistoricLeaves.blockID, 0);
			}
		}
	}
	for(int width = 3; width < 4; width++)
	{
		for(int height = 3; height < 8; height++)
		{
			for(int depth = 0; depth < 1; depth++)
			{
				world.setBlockAndMetadata(i+width, j+height, k+depth, mod_pph.prehistoricWood.blockID, 3);
				world.setBlockAndMetadata(i+width, j+height+1, k+depth, mod_pph.prehistoricLeaves.blockID, 0);
			}
		}
	}
		generateLeaves(world, random, i + 3, j + 4, k);
		generateLeaves(world, random, i - 3, j + 4, k);
	}	
		return true;
	}
	
	private boolean generateLeaves(World world, Random random, int i, int j, int k)
	{
	for(int width = -1; width < 2; width++)
	{
		for(int height = 0; height < 4; height++)
		{
			for(int depth = 0; depth < 1; depth++)
			{
			if(world.isAirBlock(i+width, j+height, k+depth))
			{
				world.setBlockAndMetadata(i+width, j+height, k+depth, mod_pph.prehistoricLeaves.blockID, 0);
			}
			}
		}
	}
	for(int width = 0; width < 1; width++)
	{
		for(int height = 0; height < 4; height++)
		{
			for(int depth = -1; depth < 2; depth++)
			{
			if(world.isAirBlock(i+width, j+height, k+depth))
			{
				world.setBlockAndMetadata(i+width, j+height, k+depth, mod_pph.prehistoricLeaves.blockID, 0);
			}
			}
		}
	}
		return true;
	}
}